package com.ruoyi.funding.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.funding.mapper.FundingSourceMapper;
import com.ruoyi.funding.domain.FundingSource;
import com.ruoyi.funding.service.IFundingSourceService;

import static com.ruoyi.common.core.context.SecurityContextHolder.getUserName;

/**
 * 资金来源Service业务层处理
 * 
 * @author ycl
 * @date 2025-01-06
 */
@Service
public class FundingSourceServiceImpl implements IFundingSourceService 
{
    @Autowired
    private FundingSourceMapper fundingSourceMapper;

    /**
     * 查询资金来源
     * 
     * @param sourceId 资金来源主键
     * @return 资金来源
     */
    @Override
    public FundingSource selectFundingSourceBySourceId(Long sourceId)
    {
        return fundingSourceMapper.selectFundingSourceBySourceId(sourceId);
    }

    /**
     * 查询资金来源列表
     * 
     * @param fundingSource 资金来源
     * @return 资金来源
     */
    @Override
    public List<FundingSource> selectFundingSourceList(FundingSource fundingSource)
    {
        return fundingSourceMapper.selectFundingSourceList(fundingSource);
    }

    /**
     * 新增资金来源
     * 
     * @param fundingSource 资金来源
     * @return 结果
     */
    @Override
    public int insertFundingSource(FundingSource fundingSource)
    {
        fundingSource.setCreateTime(DateUtils.getNowDate());
        fundingSource.setCreateBy(getUserName());
        return fundingSourceMapper.insertFundingSource(fundingSource);
    }

    /**
     * 修改资金来源
     * 
     * @param fundingSource 资金来源
     * @return 结果
     */
    @Override
    public int updateFundingSource(FundingSource fundingSource)
    {
        fundingSource.setUpdateTime(DateUtils.getNowDate());
        fundingSource.setUpdateBy(getUserName());
        return fundingSourceMapper.updateFundingSource(fundingSource);
    }

    /**
     * 批量删除资金来源
     * 
     * @param sourceIds 需要删除的资金来源主键
     * @return 结果
     */
    @Override
    public int deleteFundingSourceBySourceIds(Long[] sourceIds)
    {
        for(Long sourceId:sourceIds){
            FundingSource fundingSource = fundingSourceMapper.selectFundingSourceBySourceId(sourceId);
            fundingSource.setDeleteBy(getUserName());
            fundingSource.setDeleteTime(DateUtils.getNowDate());
            fundingSourceMapper.updateFundingSource(fundingSource);
        }
        return fundingSourceMapper.deleteFundingSourceBySourceIds(sourceIds);
    }

    /**
     * 删除资金来源信息
     * 
     * @param sourceId 资金来源主键
     * @return 结果
     */
    @Override
    public int deleteFundingSourceBySourceId(Long sourceId)
    {
        FundingSource fundingSource = fundingSourceMapper.selectFundingSourceBySourceId(sourceId);
        fundingSource.setDeleteBy(getUserName());
        fundingSource.setDeleteTime(DateUtils.getNowDate());
        fundingSourceMapper.updateFundingSource(fundingSource);

        return fundingSourceMapper.deleteFundingSourceBySourceId(sourceId);
    }
}
